// //展示列表的封装函数，消息的提示
function ElMessage(type,text,time){
    //展示框的写法
    let center_alert = document.getElementById("center_alert");
    //展示框里面的内容
    let remindText = document.getElementById("center_alert_p");
    //不同的颜色的值，从而可以标出是属于哪一个类型
    let backgroundColor;
    if (type === "warning") {//警告
        backgroundColor = "background-color: #ffb399;";
    } else if (type === "remind") {//提醒
        backgroundColor = "background-color: #d9e67d;";
    }
    //输进去的内容
    if(text){
        remindText.innerHTML=text
    }
    //转变成block状态
    center_alert.setAttribute("style","display:block;"+backgroundColor)
    //设置挂载的时间
    setTimeout(()=>{
        center_alert.setAttribute("style","display:none;" + backgroundColor)
    },time)
    
}
//确定添加confirm
function comfirmBtn(){
    //首先判断添加厨师的费用够不够、添加厨师的人数是否满足条件
    //添加成功是要介绍该请厨师的费用
    let totalIncome = document.getElementById("all_momey");
    let totalIncomeT = parseInt(totalIncome.innerHTML);
    if(chefNumber > 4){
        ElMessage("warning","您的金额不足以招聘厨师!",1500)
        return
    }else if(totalIncomeT < 100){
        ElMessage("warning","您的金额不足以招聘厨师！",1500)
        return
    }else{
        removeStyle();
        //插入新的厨师
        let chefDiv = document.createElement("div");
        chefDiv.innerHTML ="<div class='chef-icon'>"+
            "<img src=\"./img/chef.png\">"+
        "</div>"+
        "<div id =\"chef_"+chefNumber+"\"+ class='fireCooker' >\n"+
            "X"+
        "</div>"  
        chefDiv.className ="chef";
        let cookDiv = document.getElementById("cook");
        let addChefDiv = document.getElementById("add-chef");
        //在相对在添加add-chef前面俩插入新的厨师
        cookDiv.insertBefore(chefDiv,addChefDiv);
       let style = ".chef {\n" +
            "    height: 20vw;\n" +
            "}\n" +
            "\n" +
            ".cook {\n" +
            "    margin-bottom: 2vh;\n" +
            "}";    
        addStyle(style);
        addChefPage.style.display ="none";
        chef[chefNumber]= {status:"free"}; 
        let delChefDiv = document.getElementById("chef_"+chefNumber);
        const addChefButtonListener=()=>{
            deleteChef("chef_"+(chefNumber-1));
        }
        delChefDiv.removeEventListener("click",delChefButtonListener);
        delChefDiv.addEventListener("click",addChefButtonListener);
        delChefButtonListener = addChefButtonListener;
        chefNumber++;
        ElMessage("remind","招聘厨师成功！您已经有："+chefNumber+"名厨师",1500);
        totalIncomeT -= 100;
        totalIncome.innerHTML =""+ totalIncomeT;
        handerKitchen();
    }
}
//添加新的样式
function addStyle(newStyle){
    let style = document.getElementById("HTT_Style");
    style.appendChild(document.createTextNode(newStyle))
}
//删除新的样式
function removeStyle(){
    let delStyle = document.getElementById("HTT_Style");
    delStyle.removeChild(delStyle.lastChild);//因为添加进去的时候是最后的一个，删去的时候便可以删掉最后一个便可以了
}
